<?php $this->load->view('common/admin_header');?>
<link rel="stylesheet" type="text/css" href="<?=base_url('themes/admins/js/fancybox/jquery.fancybox-1.3.4.css')?>" media="screen" />
<script type="text/javascript" src="<?=base_url('themes/admins/js/fancybox/jquery.fancybox-1.3.4.pack.js')?>"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
  $("#thumbnail").fancybox({
      helpers:{title:{type:'float'}}
  });
});
</script>
<div class="block">
  <div class="block_head">
    <div class="bheadl"></div>
    <div class="bheadr"></div>
    <h2><?=$lang['global_lable_36']?></h2>
    <ul>
      <li><a href="<?=site_url('admins/menuimage')?>"><?=$lang['global_lable_41']?></a></li>
    </ul>
  </div>
  <!-- .block_head ends -->
  <div class="block_content">
    <?php $this->load->view('common/notify');?>
  <form id="form" action="<?=site_url('admins/menuimage/modify');?>" method="post">
    <input type="hidden" name="edit_id" value='<?=set_value('edit_id',isset($edit_id)?$edit_id:'')?>' />
      <?php $img_images=set_value('menu_icon',isset($menu_icon) && file_exists($menu_icon)?$menu_icon:'');?>
      <?php $show_image=!empty($img_images)?imagelib::resize_thumb($img_images,260,260):'themes/admins/img/no_image.png';?>
      <p>
        <a id="thumbnail" href="<?=base_url().(!empty($img_images)?$img_images:'themes/admins/img/no_image.png')?>" class="thumbnail">
          <img id="img_images" src="<?=base_url().$show_image?>" class="preview-img" style="max-width:300px">
        </a>
      </p>
      <p>
        <label><?=$lang['content_lable_36']?>:</label>
        <div id="simple-btn" data-tag="display_logo" class="btn btn-success js-fileapi-wrapper">
           <div class="js-browse">
              <input type="file" name="Filedata">
           </div>
           <div class="js-upload" style="display: none">
              <div class="progress progress-success">
                <div class="js-progress bar"></div>
              </div>
              <span class="btn-txt">Uploading (<span class="js-size"></span>)</span>
           </div>
        </div>
        <input id="old_images" type="hidden" name="menu_icon" value="<?=set_value('menu_icon',isset($menu_icon) && file_exists($menu_icon)?$menu_icon:'')?>">
        <a href="#clear_img" tag="images" class="btn" style="display:<?=!empty($img_images)?'':'none'?>"><i class="icon-trash"></i> <?=$lang['content_lable_39']?></a>
        <br>
      </p>

      <p style="display: none">
          <label>所屬頁面:</label>
          <select name="category">
              <!--  <option value=''>--請選擇所屬頁面--</option> -->
              <?php foreach($ccc as $k=>$c):?>
                  <option value='<?=$k?>' <?php echo set_select('category',$k);?> <?=isset($category) && $category==$k?'selected':''?>><?=$c?></option>
              <?php endforeach;?>
          </select>
          <span class="note required">*必選內容</span>
      </p>
      <p style="display: none">
          <label>廣告位置:</label>
          <select name="position">
              <!-- <option value=''>--請選擇選擇位置--</option> -->
              <?php foreach($positions as $k=>$p):?>
                  <option value='<?=$k?>' <?php echo set_select('position',$k);?> <?=isset($position) && $position==$k?'selected':''?>><?=$p?></option>
              <?php endforeach;?>
          </select>
      </p>
      <p>
        <label><?=$lang['content_lable_19']?>(繁體):</label>
        <input type="text" class="text small" name="title" value='<?=set_value('title',isset($title)?$title:'')?>'/>
        <span class="note required">*<?=$lang['global_lable_35']?></span>
      </p>
      <p>
	    <label><?=$lang['content_lable_19']?>(English):</label>
	    <input type="text" class="text small" name="entitle" value='<?=set_value('entitle',isset($entitle)?$entitle:'')?>'/>
	    <span class="note required">*<?=$lang['global_lable_35']?></span>
      </p>
      <p>
        <label><?=$lang['content_lable_20']?>:</label>
        <input type="text" class="text small" name="bg_color" value='<?=set_value('bg_color',isset($bg_color)?$bg_color:'')?>'/>
      </p>
      <p>
        <label><?=$lang['content_lable_38']?>:</label>
        <input type="text" class="text small" name="links" value='<?=set_value('links',isset($links)?$links:'')?>'/>
      </p>
      <p>
        <label><?=$lang['global_lable_17']?>:</label>
        <input type="text" class="text small" name="sort_order" value='<?=set_value('sort_order',isset($sort_order)?$sort_order:'0')?>'/>
      </p>
      <p>
        <label><?=$lang['global_lable_16']?>:</label>
        <input type="radio" class="radio" name="status" value="1" <?=set_radio('status', '1', TRUE); ?> <?=isset($status) && $status==1?'checked':''?> />
        <span><?=$lang['global_lable_37']?></span>
        <input type="radio" class="radio" name="status" value="2" <?=set_radio('status', '2'); ?> <?=isset($status) && $status==2?'checked':''?> />
        <span><?=$lang['global_lable_38']?></span>
      </p>
      <p>
        <input class="btn btn-primary" type="submit" name="btn_save" value="<?=$lang['global_lable_12']?>" />
        <input class="btn" type="reset" value="<?=$lang['global_lable_13']?>"/>
      </p>
    </form>
  </div>
  <!-- .block_content ends -->
  <div class="bendl"></div>
  <div class="bendr"></div>
</div>
<!-- .block ends -->
<script type="text/javascript" charset="utf-8">
window.FileAPI = {
  debug: true, // debug mode
  cors: false,    // if used CORS, set `true`
  media: false,   // if used WebCam, set `true`
  flashUrl:"<?=base_url('themes/admins/js/jquery.fileapi/FileAPI/FileAPI.flash.swf')?>",
  staticPath:'themes/admins/js/jquery.fileapi/FileAPI/' // path to *.swf
};
</script>
<script src="<?=base_url('themes/admins/js/jquery.fileapi/FileAPI/FileAPI.min.js')?>"></script>
<script src="<?=base_url('themes/admins/js/jquery.fileapi/FileAPI/FileAPI.exif.js')?>"></script>
<script src="<?=base_url('themes/admins/js/jquery.fileapi/jquery.fileapi.js')?>"></script>
<script type="text/javascript" charset="utf-8">
  $(document).ready(function($) {
    var folder=encodeURIComponent('uploads/adv_img/');
    $('#simple-btn').fileapi({
       url:"<?=site_url('admins/upload/single_upload')?>",
       data: {'folder':folder,'_size':'260x260','_element_id':'images','_admin_id':"<?=$this->nsession->userdata('admin_id')?>",'_nickName':"<?=$this->nsession->userdata('nick_name')?>"},
       multiple: false,
       accept: 'image/*',
       maxSize: 2 * FileAPI.MB,
       autoUpload: true,
       clearOnComplete:true,
       elements: {
          size: '.js-size',
          active: { show: '.js-upload', hide: '.js-browse' },
          progress: '.js-progress'
       },
       onComplete:function(evt,uiEvt){
        var error = uiEvt.error;
        var result = uiEvt.result; // server response
        if(!error && result){
          // console.log(result);
          if(result.error){
            alert(result.error);
            return;
          }
          $("#old_"+result.element_id).val(result.img_path);
          $("#img_"+result.element_id).attr('src',result.thumb_img);
          if ($('#thumbnail').length)
            $("#thumbnail").attr('href',result.http_img);
          if ($('a[href="#clear_img"]').length)
            $('a[href="#clear_img"]').show();
        }
      }
    });

    //清除圖片
    $('a[href="#clear_img"]').click(function() {
      var obj=$(this);
      var action="<?=site_url('admins/upload/delete')?>";
      var defaule_img="<?=base_url('themes/admins/img/no_image.png')?>";
      clear_img(obj,action,defaule_img);
      return false;
    });

  });
</script>
<?php $this->load->view('common/admin_footer');?>

